import 'package:dk_flutter_base/dk_ui.dart';
import 'package:dk_flutter_module_sale/common/widget/dk_common_image.dart';
import 'package:dk_flutter_module_sale/sale/Image/image_url.dart';

class ImageWidget extends StatelessWidget {
  final VoidCallback tapAction;
  final VoidCallback deleteAction;
  final String imageURL;
  final bool lookOnly;
  ImageWidget(
      {this.imageURL = "",
      this.lookOnly = true,
      this.tapAction,
      this.deleteAction});
  @override
  Widget build(BuildContext context) {
    double padding = 6;
    return Container(
      color: Colors.white,
      child: Stack(
        children: <Widget>[
          Positioned(
            top: padding,
            bottom: padding,
            left: padding,
            right: padding,
            child: GestureDetector(
              child: getImageWidget(),
              onTap: () {
                this.tapAction();
              },
            ),
          ),
          Positioned(
              top: 0,
              bottom: 0,
              left: 0,
              right: 0,
              child: DkVisibilityCompose(
                  VisibilityComposeOption.invisible((BuildContext context) {
                return GestureDetector(
                  onTap: () {
                    this.tapAction();
                  },
                  child: Container(
                    child: Center(
                      child: Image.network(
                        AppNetWorkImage.playIcon,
                        height: 22,
                        width: 22,
                      ),
                    ),
                  ),
                );
              }, visible: this.imageURL != AppNetWorkImage.cameraIcon))),
          Positioned(
            top: 0,
            right: 0,
            child: DkVisibilityCompose(VisibilityComposeOption.invisible((BuildContext context){
              return GestureDetector(
                onTap: (){
                  this.deleteAction();
                },
                child: Container(
                  color: Colors.transparent,
                  child: Padding(
                    padding: const EdgeInsets.only(left: 20,bottom: 20),
                    child: Image.network(
                      AppNetWorkImage.deleteIcon,
                      height: 12,
                      width: 12,
                    ),
                  ),
                ),
              );
            },visible: this.lookOnly == false))),
        ],
      ),
    );
  }

  bool isNetworkImage(String url) {
    if (url.startsWith("http")) {
      return true;
    } else {
      return false;
    }
  }

  Widget getImageWidget() {
    return DkImage(
      path: imageURL,
    ).build();
  }
}
